<?
#####################################################
#  COPYRIGHT NOTICE
#####################################################
# In the following statements, the term "this 
# program" refers to all files associated with the
# execution and distribution of Adtrackz.
#
# This Program is Copyright 2004 Jonah Klimack.
# All Rights Reserved. 
#
# Selling the code for this program, modifying 
# and/or redistributing the code for this program
# in part or in whole over the Internet or in any 
# other medium is expressly forbidden. Violators
# will be prosecuted to the fullest extent of the law
# Copyright and header information may not be
# modified.
#
# This program is distributed "as is" and without 
# warranty of any kind, either express or implied.
# In no event shall the liability of Jonah Klimack 
# for any damages, losses and/or causes of 
# action exceed the total amount paid by the 
# user for this software.		
#####################################################
# DO NOT MODIFY ANYTHING IN THIS FILE
#####################################################

require "header.php";

?>
<p class="heading">
Modify or Add New Groups
</p>
<p>
You can create groups to help organize your campaigns. For example, you could create a group called google for all of your google ads. To add a group, fill out one of the forms and press Modify Groups. To delete a group, empty the field of the group you would like to delete and press Modify Groups.
</p>
<?

if ($submit)
{
	$msg = "";
	for ($i=0;$i<=count($groupids)-1;$i++)
	{
		$mgroup = mysql_fetch_row(mysql_query("select groupname from adtrackz_groups where ID='$groupids[$i]'"));
		if (!$groupnames[$i])
		{
			//set all campaigns with this group to default
			mysql_query("update adtrackz_campaigns set groupID='0' where groupID='$groupids[$i]'");
			mysql_query("delete from adtrackz_groups where ID='$groupids[$i]'");
			$msg .= "$mgroup[0] has been deleted.<br>";
		}
		else
		{
			mysql_query("update adtrackz_groups set groupname='$groupnames[$i]' where ID='$groupids[$i]'");
			if ($groupnames[$i] != $mgroup[0])
				$msg .= "$mgroup[0] has been changed to $groupnames[$i].<br>";
		}
	}	
	foreach ($newgroups as $g)
	{
		if ($g)
		{
			mysql_query("insert into adtrackz_groups values ('','$g')");
			$msg .= "$g has been added.<br>";
		}
	}
	if ($msg)
		alert ($msg);
}
?>



<form action="groups.php" method="post">
<table width="380" border="1" cellspacing="0" cellpadding="5" align="center" bgcolor="white" bordercolor="white">
			<?
			$groupdata = mysql_query("select * from adtrackz_groups order by 'id'") or die("Invalid query: " . mysql_error()); 			
			$i=1;
			while($group1 = mysql_fetch_row($groupdata))
			{
				echo "<tr><td>Group $i</td><td><input type=\"text\" name=\"groupnames[]\" value=\"$group1[1]\" maxlength=\"25\"><input type=\"hidden\" name=\"groupids[]\" value=\"$group1[0]\"</td></tr>";
				$i++;
			}			
			?>
<tr>
	<td>New Group</td>
	<td><input type="text" maxlength="25" name="newgroups[]"></td>
</tr>
<tr>
	<td>New Group</td>
	<td><input type="text" maxlength="25" name="newgroups[]"></td>
</tr>
<tr>
	<td>New Group</td>
	<td><input type="text" maxlength="25" name="newgroups[]"></td>
</tr>
</table>
<br><br>
<center>
<input type="submit" name="submit" value="Modify Groups"  >
</center>
<br>
</form>




<?



require "footer.php";
?>